$(function(){
    $("#news_category_id").change(function(){
        $("#next_select").html("<select name='sec_cate_id' id='sec_cate_id'></select>");
        $.get(
            "/admins/news/get_second_categories",
            {"cate_id":$("#news_category_id").val()},
            function(data){
                var datas = eval(data);
                $.each(datas,function(i){
                    $("<option value='"+datas[i].id+"'>"+datas[i].cataname+"</option>").appendTo($("#sec_cate_id"));
                });
            });
    });
    $("#sptitle_div").children("div").click(function(){
        if(jQuery(this.children[0]).prop("checked")){
            jQuery(this.children[0]).prop("checked",false);
            jQuery(this.children[0]).attr("checked",false);
            $("#choosed_sptitle").html($("#choosed_sptitle").html().replace(" || " + jQuery(this.children[1]).html(),""));
            $("#choosed_sptitle").html($("#choosed_sptitle").html().replace(jQuery(this.children[1]).html(),""));
        }else{
            jQuery(this.children[0]).prop("checked",true);
            jQuery(this.children[0]).attr("checked",true);
            $("#choosed_sptitle").append(" || " + jQuery(this.children[1]).html());
        }
    });
    $(".sptitle_span").click(function(){
        if($("#sptitle_div").is(":visible") == false){
            $(".myCloseButton").show();
            $("#sptitle_div").show();
        }else{
            $(".myCloseButton").hide();
            $("#sptitle_div").hide();
        }
    });
    $(".myCloseButton").click(function(){
        $(".myCloseButton").hide();
        $("#sptitle_div").hide();
    });

    $("#category_id").change(function(){
        var category_id = $("#category_id").val();
        $.get(
            "/categories/"+ category_id+"/childrens",
            function(data){
                var options = "<option>请选择</option>"
                var datas = eval(data);
                $.each(datas,function(i){
                    options += "<option value='"+datas[i].id+"'>"+datas[i].cataname+"</option>"
                });
                $("#children_id").html(options);
            });
    });
});
